<!doctype html>
<html>
<head>
<?php $this->load->view('admin/common_head'); ?>
</head>
<body>
<div class="wrap J_check_wrap">
	<div class="nav">
		<ul class="cc">
			<li><a href="<?php echo site_url('admin/announce/index'); ?>">公告列表</a></li>
			<li><a href="<?php echo site_url('admin/announce/index?action=expired'); ?>">过期公告</a></li>
			<li class="current"><a href="<?php echo site_url('admin/announce/add'); ?>">+ 添加公告</a></li>
		</ul>
	</div>
	<form id="J_announce_form" class="J_ajaxForm" action="<?php echo site_url('admin/announce/do_add'); ?>" method="post">
		<div class="h_a">添加公告</div>
		<div class="table_full">
			<table width="100%">
				<colgroup>
				<col class="th">
				<col width="400">
				</colgroup>
				<tr>
					<th>显示顺序</th>
					<td><input name="vieworder" type="text" class="input length_5" /></td>
					<td></td>
				</tr>
				<tr>
					<th>有效时间</th>
					<td><span class="must_red">*</span>
						<input name="start_date" type="text" class="input length_2 J_date mr20" />
						<span class="mr20">至</span>
						<input name="end_date" type="text" class="input length_2 J_date" /></td>
					<td></td>
				</tr>
				<tr class="J_radio_change">
					<th>公告类别</th>
					<td>
						<ul class="single_list cc">
							<li><label><input name="type" type="radio" value="text" checked="checked" data-arr="J_announce_content">文字公告</label></li>
							<li><label><input name="type" type="radio" value="url" data-arr="J_announce_link">链接公告</label></li>
						</ul>
					</td>
					<td></td>
				</tr>
				<tr>
					<th>公告标题</th>
					<td>
						<span class="must_red">*</span>
						<input name="subject" type="text" class="input length_5" placeholder="公告标题" /></td>
					<td></td>
				</tr>
				<tbody id="J_announce_content" class="J_radio_tbody">
					<tr>
						<th>公告内容</th>
						<td colspan="2">
							<span class="must_red">*</span>
							<textarea id="J_textarea" name="content" style="width:600px;height:200px;"></textarea>
						</td>
					</tr>
				</tbody>
				<tbody id="J_announce_link" class="J_radio_tbody">
					<tr>
						<th>公告链接</th>
						<td>
							<span class="must_red">*</span>
							<input name="url" type="text" class="input length_6" placeholder="公告指向的链接地址" />
						</td>
						<td></td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="btn_wrap">
			<div class="btn_wrap_pd">
				<button class="btn btn_submit J_ajax_submit_btn" id="J_announce_sub" type="submit">提交</button>
			</div>
		</div>
	</form>
</div>
<?php $this->load->view('admin/common_footer'); ?>
<script>
Wind.use('ajaxForm', function() {
	//考虑编辑器 改成submit事件，ajaxform代码基本同common.js
	var btn = $('#J_announce_sub');
	$('#J_announce_form').on('submit', function(e) {
		e.preventDefault();
		var form = $(this);

		form.ajaxSubmit({
			dataType	: 'json',
			beforeSubmit: function(arr, $form, options) {
				var text = btn.text();
				
				//按钮文案、状态修改
				btn.text(text +'中...').prop('disabled',true).addClass('disabled');
			},
			success		: function(data, statusText, xhr, $form) {
				var text = btn.text();
			
				//按钮文案、状态修改
				btn.removeClass('disabled').text(text.replace('中...', '')).parent().find('span').remove();
			
				if( data.state === 'success' ) {
					$( '<span class="tips_success">' + data.message + '</span>' ).appendTo(btn.parent()).fadeIn('slow').delay( 1000 ).fadeOut(function() {
						if(data.referer) {
							//返回带跳转地址
							window.location.href = data.referer;
						}else {
							reloadPage(window);
						}
					});
				}else if( data.state === 'fail' ) {
					$( '<span class="tips_error">' + data.message + '</span>' ).appendTo(btn.parent()).fadeIn( 'fast' );
					btn.removeProp('disabled').removeClass('disabled');
				}
			}
		});
	});
});
</script>
</body>
</html>